package org.tcx.web.ajax.validators;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import org.apache.commons.validator.Validator;
import org.apache.commons.validator.ValidatorException;
import org.apache.commons.validator.ValidatorResources;
import org.apache.commons.validator.ValidatorResult;
import org.apache.commons.validator.ValidatorResults;
import org.tcx.common.DomUtil;
import org.tcx.common.json.JsonUtil;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Temp {
	public static void main(String[] args) throws IOException, SAXException, ValidatorException {
		InputStream validator_in = Temp.class.getClassLoader()
				.getResourceAsStream("ajax.validator.xml");
		System.out.println(validator_in);
		ValidatorResources resources = new ValidatorResources(validator_in);
		Validator validator = new Validator(resources, "/TestCase/saveTestCase");
		JSON json = JSONSerializer.toJSON("{precondition:'haha'}");
		validator.setParameter(Validator.BEAN_PARAM, json);
		ValidatorResults results = validator.validate();
		System.out.println("OK");
		StringWriter writer = new StringWriter();
		JsonUtil.toJsonStr(results,writer );
		System.out.println(writer.toString());
	}
}
